<%@page import="com.grom.service.SecurityService"%>
<%@page import="com.grom.po.Security"%>
<%@page import="com.grom.util.SecurityUtil"%>
<%@page import="com.grom.po.GcmsUser"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/js/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/js/themes/icon.css">
<script type="text/javascript" src="<%=request.getContextPath() %>/js/jquery-1.6.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/js/jquery.easyui.min.js"></script>

<script type="text/javascript">
$(function(){
	$('#loginInfoEdit').dialog({  
	    title : 'Brand 录入',  
	    modal: true,  
	    collapsible : true,    
	    resizable : true   
	});  
	$('#loginInfoEdit').dialog('close');
});


function showAddDialog(){
	$('input').each(function(){
		$(this).val('');
	});
	$('select').each(function(){
		$(this).val('');
	});
	$('#loginInfoEdit').dialog('open');
}

function loginInfoEdit(){
	$('brandForm').submit();
	$('#loginInfoEdit').dialog('close');
}

function viewDetail(){
	var itemId =  $('#tt').datagrid('getSelected').itemid;
	$.ajax({
	    url: '<%=request.getContextPath()%>/SecurityAction/getDetail.do?itemid='+itemId,
	    type: 'GET',
	    timeout: 1000,
	    error: function(){
	        alert('Error getting response!');
	    },
	    success: function(json){
	        var security = eval(json);
	        $('#ID').val(security.ID);
	        $('#securityName').val(security.securityName);
	        $('#actionUrl').val(security.actionUrl);
	        $('#parentID').val(security.parentID);
			$('#loginInfoEdit').dialog('open');
	    }
	});
}


function doDelete(){
	var itemId =  $('#tt').datagrid('getSelected').itemid;
	if (itemId){  
        $.messager.confirm('Confirm','Are you sure you want to remove this user?',function(r){  
            if (r){  
				$('#deleteId').val(itemId);
				$('#deleteForm').submit();
            }  
        });  
    } 
}
function doSearch(){
	$('#searchForm').submit();
}
</script>
</head>
<body>
<div style="display: none;">
	<form name="deleteForm" id="deleteForm" action="<%=request.getContextPath() %>/SecurityAction/doDelete.do">
		<input type="text" name="deleteId" id="deleteId"/>
	</form>
</div>
<div style="font-size: 10px;">
	<form id="searchForm" name="searchForm" action="<%=request.getContextPath() %>/SecurityAction/conditionSelect.do" method="post">
      <label>权限名称：</label>  
      <input type="text" name="securityName_s" id="securityName_s" ></input>  
      <a href="#" class="easyui-linkbutton" iconCls="icon-search" plain="true" onclick="doSearch()">search</a>
    </form>
</div>
<table id="tt" class="easyui-datagrid"  singleSelect="true"
        title="DataGrid with Toolbar" iconCls="icon-save"  
        toolbar="#tb">  
    <thead>  
        <tr>  
            <th field="itemid" width="80">Item ID</th>  
            <th field="securityName" width="100">权限名称</th>  
            <th field="actionUrl" width="180" align="right">权限动作</th>  
            <th field="parentID" width="80" align="right">父节点ID</th>   
        </tr>  
    </thead>  
    <tbody>     
    	<%
    		List<Security> allSecuritys = (List<Security>)request.getAttribute("allSecuritys");
    		for(Security security : allSecuritys){
    	%>
        <tr>                             
            <td><%=security.getID() %></td>              
            <td><%=security.getSecurityName() %></td>              
            <td><%=security.getActionUrl() %></td>              
            <td><%=security.getParentID() %></td>                          
        </tr>  
    	<%
    		}
    	%>                         
    </tbody>
</table>  
<div id="tb">  
   <%
	if(session.getAttribute("USER")!=null){
%>
    <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="showAddDialog()">Add</a>  
    <a href="#" class="easyui-linkbutton" iconCls="icon-cut" plain="true" onclick="viewDetail()">view/update</a>  
    <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="doDelete()">Delete</a> 
    <a href="#" class="easyui-linkbutton" iconCls="icon-back" plain="true" onclick="javascript:alert('我觉着这个翻页不实用，设置下条件吧！')">pre page</a> 
    <a href="#" class="easyui-linkbutton" iconCls="icon-back" plain="true" onclick="javascript:alert('我觉着这个翻页不实用，设置下条件吧！')">next page</a> 
<%
	}
%>
</div>  


<!-- 编辑 -->  
<div id="loginInfoEdit"  
    style="padding: 5px; width: 300px; height: 250px;">  
    <h5 id="loginInfoEdit_message" style="color: red;"></h5>  
    <div class="ToolTip_Form" id="table_loginInfoEdit" onkeydown="if(event.keyCode==13){loginInfoEdit();}">  
       <form id="securityForm" name="securityForm" action="<%=request.getContextPath() %>/SecurityAction/doSave.do" method="post">
       <input type="hidden" name="ID" id="ID" value="" />
       <ul>    
            <li>  
                <label>权限点：</label>  
                <input type="text" class="easyui-validatebox" name="securityName" id="securityName" maxlength="60" required="true"></input>  
            </li>  
            <li>  
                <label>actionURL：</label>  
                <input type="text" class="easyui-validatebox" name="actionUrl" id="actionUrl" maxlength="60" required="true"></input>  
            </li> 
            <li>  
                <label>parentID：</label>  
                <select class="easyui-validatebox" name="parentID" id="parentID" maxlength="60">
                	<option value="ROOT">ROOT</option>
                	<%
                		List<Security> parents = SecurityService.instance.getAllParentSecurity();
                		for(Security parent : parents){
                	%>
                		<option value="<%=parent.getID() %>"><%=parent.getSecurityName() %></option>
                	<%
                		}
                	%>
                </select>  
            </li> 
            <li>  
             	<a href="#" class="easyui-linkbutton" onclick="$('#securityForm').submit();">保存</a>
            	<a href="#" class="easyui-linkbutton" onclick="$('#loginInfoEdit').dialog('close');">放弃操作</a>
            </li>  
        </ul>  
       </form>
    </div>  
</div>  
</body>
</html>